local map = require('utils.vim').map
local cmd = require('utils.vim').cmd
local helper_map = require('helper.neotree_config_mapping')
local helper_cmd = require('helper.neotree_config_commands')

return {
    "nvim-neo-tree/neo-tree.nvim",
    lazy = false,
    dependencies = {
        { "nvim-lua/plenary.nvim", pin=true},
        { "MunifTanjim/nui.nvim", pin=true},
    },
    config = function()
        local neotree = require("neo-tree")
        neotree.setup({
            -- https://github.com/nvim-neo-tree/neo-tree.nvim/blob/a7d6f05e57487326fd70b24195c3b7a86a88b156/lua/neo-tree/defaults.lua
            hide_root_node = true,
            retain_hidden_root_indent = false,
            enable_git_status = false,
            enable_modified_markers = false,
            use_popups_for_input = false, -- not floats for input
            -- selft defined command
            -- Thanks:https://github.com/nvim-neo-tree/neo-tree.nvim/issues/791
            commands = helper_cmd,
            window = {
                --c(d), z(p)
                mappings = helper_map,
            },
            default_component_configs = {
                icon = {
                    folder_closed = "",
                    folder_open = "",
                },
            },
            -- Thanks: https://www.reddit.com/r/AstroNvim/comments/129rvb1/override_a_few_neotree_options/
            filesystem = {
                filtered_items = {
                    show_hidden_count = false,
                    hide_by_name = {
                        "node_modules",
                    },
                },
                components = {
                    -- hide file icon
                    icon = function(config, node, state)
                        if node.type == 'file' then
                            return {
                                text = "",
                                highlight = config.highlight,
                            }
                        end
                        return require('neo-tree.sources.common.components').icon(config, node, state)
                    end,
                } -- components
            }, -- filesystem
            event_handlers = {{
                event = "neo_tree_buffer_enter",
                handler = function(arg)
                    vim.cmd [[ setlocal relativenumber ]]
                end,
            }},
        })
    end,
}
-- EOP
